hamburgers = input()
b, s, c = map(int, input().split())
q, w, e = map(int, input().split())
p = int(input())
F = str.count
B = F(hamburgers, 'B')
S = F(hamburgers, 'S')
C = F(hamburgers, 'C')
l = -1
r = 10 ** 20
while l < r-1:
m = (l + r) // 2
if q * max(0, B * m - b) + w * max(0, S * m - s) + e * max(0, C * m - c) <= p:
l = m
else:
r = m
print(l)
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, a, b) for (int i = a; i >= b; i--)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define fo(i, a, n) for (int i = a; i <= n; i++)
#define repll(i, a, n) for (lli i = a; i <= n; i++)
#define mkp make_pair
#define pb emplace_back
#define ff first
#define ss second
#define ll long long
#define lli long long int
#define ii int, int
#define pii pair<int, int>
#define pll pair<long, long>
#define plli pair<long long int, long long int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vlli vector<long long int>
#define vpii vector<pair<int, int>>
#define vplli vector<pair<long long int, long long int>>
#define vvlli vector<vector<long long int>>
#define MAXLL 1e18
#define endl '\n'
#define sp ' '
#define dsort(v) sort(v.begin(), v.end(), greater<int>())
#define asort(v) sort(v.begin(), v.end())
#define uniq(v) v.erase(unique(v.begin(), v.end()), v.end())
#define all(v) v.begin(), v.end()
#define umap unordered_map
#define uset unordered_set
#define sz(x) ((int)(x).size())
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define pr(x) cout << x
#define prsp(x) cout << x << sp
#define prln(x) cout << x << endl
#define fastio ios_base::sync_with_stdio(0), cin.tie(0)
using namespace std;
#include<bits/stdc++.h>
using namespace std;
ll gcd(ll a, ll b)
{
if(b == 0) {
return a;
}
else {
return gcd(b, a % b);
}
}
long long lcm(long long a,long long b){
if(a>b)
return (a/gcd(a,b))*b;
else
return (b/gcd(a,b))*a;
}
const int mod = 1000000007;
void solve()
{
string s;
cin>> s;
ll b1,b2,b3,p1,p2,p3;
cin >> b1 >> b2 >> b3 >> p1 >> p2 >> p3;
ll r;
cin >> r;
ll a=0,b=0,c=0;
for(auto ch:s){
if(ch=='B') a++;
else if(ch=='S') b++;
else c++;
}
ll low=0,high=r+101;
while(low<=high){
ll mid=low+(high-low)/2;
ll z=0;
ll r1=max(a*mid-b1,z);
ll r2=max(b*mid-b2,z);
ll r3=max(c*mid-b3,z);
ll price=r1*p1+r2*p2+r3*p3;
if(price<=r) low=mid+1;
else high=mid-1;
}
cout<<high;
}
int main()
{
fastio;
solve();
}
129A - Cookies | 1367B - Even Array |
136A - Presents | 1450A - Avoid Trygub |
327A - Flipping Game | 411A - Password Check |
1520C - Not Adjacent Matrix | 1538B - Friends and Candies |
580A - Kefa and First Steps | 1038B - Non-Coprime Partition |
43A - Football | 50A - Domino piling |
479A - Expression | 1480A - Yet Another String Game |
1216C - White Sheet | 1648A - Weird Sum |
427A - Police Recruits | 535A - Tavas and Nafas |
581A - Vasya the Hipster | 1537B - Bad Boy |
1406B - Maximum Product | 507B - Amr and Pins |
379A - New Year Candles | 1154A - Restoring Three Numbers |
750A - New Year and Hurry | 705A - Hulk |
492B - Vanya and Lanterns | 1374C - Move Brackets |
1476A - K-divisible Sum | 1333A - Little Artem |